﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using NUnit.Framework;


namespace TestDBSourceToolsLibNUnit
{
    public class FileHelper
    {
        public void DeleteFilesInDir(string strDir)
        {
            if (System.IO.Directory.Exists(strDir))
            {
                System.IO.DirectoryInfo baseDirInfo = new System.IO.DirectoryInfo(strDir);
                foreach (System.IO.DirectoryInfo oDir in baseDirInfo.GetDirectories())
                {
                    oDir.Delete(true);
                }
                foreach (System.IO.FileInfo oFile in baseDirInfo.GetFiles())
                {
                    System.IO.File.Delete(oFile.FullName);
                }
            }
            
        }


        internal void CompareDirectories(string sourceDir, string targetDir)
        {
            DBSourceToolsLib.FileComparer.DirectoryList oDirectoryList =
                new DBSourceToolsLib.FileComparer.DirectoryList(sourceDir, targetDir);

            //bool isCompareOK = true ;
            for (int i = 0; i < oDirectoryList.SourceFiles.Count; i++)
            {
                DBSourceToolsLib.FileComparer.IDCFileObject oDCSource = oDirectoryList.SourceFiles[i];
                Assert.IsTrue(oDirectoryList.TargetFiles.Count > i, " Target files missing : " +
                    oDCSource.GetRelativeFileName());
                DBSourceToolsLib.FileComparer.IDCFileObject oDCTarget = oDirectoryList.TargetFiles[i];
                Assert.IsTrue(oDCSource.GetRelativeFileName().CompareTo(oDCTarget.GetRelativeFileName()) == 0,
                    " Source " + oDCSource.GetRelativeFileName() + " != "
                    + oDCTarget.GetRelativeFileName());

                if (oDCSource.isFile())
                {
                    DBSourceToolsLib.FileComparer.FileComparer oFileComparer
                        = new DBSourceToolsLib.FileComparer.FileComparer(
                            oDCSource.GetFullPath(),
                            oDCTarget.GetFullPath());
                    Assert.IsTrue(oFileComparer.AreFilesEqual(), "Invalid " + oDCSource.GetFullPath()
                        + " and " + oDCTarget.GetFullPath());
                }
            }

        }

        public void CompareFiles(string controlFile, string outputFile)
        {
            DBSourceToolsLib.FileComparer.FileComparer oFileComparer =
                new DBSourceToolsLib.FileComparer.FileComparer(controlFile, outputFile);

            Assert.IsTrue(oFileComparer.SourceFileExists(), "could not find source file : \n"
                + controlFile);

            Assert.IsTrue(oFileComparer.TargetFileExists(), "could not find target file : \n"
                + outputFile);

            Assert.IsTrue(oFileComparer.AreFilesEqual(), "Files are different : \n"
                + controlFile + "\n"
                + outputFile);

        }

    }
}
